<template>
  <div class="wrap">
    <div class="page-head">
      <a-breadcrumb>
        <a-breadcrumb-item>{{ $t('data.data.60zec2kbxiw0') }}</a-breadcrumb-item>
      </a-breadcrumb>
    </div>
    <div class="data-demo" @refresh="getData">
      <div class="data-demo-info">
        <div class="top">
          <div class="statistics">
            <div class="search-demo">
              <a-form ref="formRef" layout="inline" :model="form">
                <div class="inputGroup">
                  <a-form-item :label="$t('data.data.60zec2kbzzk0')" feedback field="districtId">
                    <a-range-picker :model-value="[form.data.startTime, form.data.endTime]"
                      @change="form.data.startTime = $event?.[0]; form.data.endTime = $event?.[1]"
                      value-format="YYYY-MM-DD HH:mm:ss"></a-range-picker>
                  </a-form-item>
                  <a-space>
                    <a-button @click="getData" type="primary" html-type="submit">
                      <template #icon>
                        <icon-search />
                      </template>
                      {{ $t('data.data.60zec2kc0ns0') }}
                    </a-button>
                    <a-button type="outline" @click="formRef?.resetFields()">
                      <template #icon>
                        <icon-refresh />
                      </template>
                      {{ $t('data.data.60zec2kc1x00') }}
                    </a-button>
                  </a-space>
                </div>
              </a-form>
            </div>
            <div class="statistics-demo">
              <statisticsList :detail="form.detail"></statisticsList>
            </div>
          </div>
          <div class="stay-time">
            <div class="title">{{ $t('data.data.60zec2kc26g0') }}</div>
            <div class="chart">
              <stayPeriod :stayPeriodList="form.stayPeriodList"></stayPeriod>
            </div>
          </div>
        </div>
        <div class="bottom">
          <div class="variety">
            <div class="chart">
              <aircraftType :aircraftTypeList="form.aircraftTypeList"></aircraftType>
            </div>
          </div>
          <div class="trend">
            <div class="chart">
              <detectingTrend :detectingTrendList="form.detectingTrendList"></detectingTrend>
            </div>
          </div>
        </div>
        <div class="whilte-list">
          <whiteListData :detail="form.detail"></whiteListData>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { apiDataList } from '@/api/data'
import dayjs from 'dayjs';
const statisticsList = defineAsyncComponent(() => import('./components/statisticsList.vue'))
const stayPeriod = defineAsyncComponent(() => import('./components/stayPeriod.vue'))
const aircraftType = defineAsyncComponent(() => import('./components/aircraftType.vue'))
const detectingTrend = defineAsyncComponent(() => import('./components/detectingTrend.vue'))
const whiteListData = defineAsyncComponent(() => import('./components/whiteListData.vue'))
const formRef = ref()
const local = useLocal()
// const emit = defineEmits(['refresh'])
// const refresh = () => {
//   emit('refresh')
// }
// 查找
const form = reactive({
  // auths:[],
  // allAuths:[],
  data: {
    startTime: dayjs().subtract(7, 'day').format('YYYY-MM-DD HH:mm:ss'),
    endTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
    uid: local.usermsg.id == 3 ? 0 : local.usermsg.id
  } as any,
  loading: false,
  detail: {},
  stayPeriodList: [],
  aircraftTypeList: [],
  detectingTrendList: []
})
// const handleSubmit = ({ values, errors }: any) => {
//   console.log('values:', values, '\nerrors:', errors)
// }
// 数据统计列表
const getData = async () => {
  const { code, data } = await apiDataList({
    ...form.data,
    startTime: Number(dayjs(form.data.startTime).format('X')),
    endTime: Number(dayjs(form.data.endTime).format('X')),
  })
  if (code != 200) return;
  form.detail = data
  form.stayPeriodList = data.uavDayHourParking
  form.aircraftTypeList = data.uavTypeList
  form.detectingTrendList = data.uavAvgDayList
}
onBeforeMount(() => {
  getData()
})
</script>

<style lang="less" scoped>
.wrap {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

  .data-demo {
    flex: 1;
    // width: 100%;
    height: 100%;
    overflow: auto;
    margin-right: 10px;

    >.data-demo-info {
      width: 100%;
      height: 100%;
      overflow: auto;
      display: flex;
      flex-direction: column;
      gap: 16px;

      >div {
        width: 100%;
        border-radius: 10px;
      }

      >.top {
        display: flex;
        justify-content: space-between;
        gap: 16px;
        height: 400px;

        >.statistics {
          width: calc(50% - 8px);
          height: 100%;
          border-radius: 10px;
          display: flex;
          flex-direction: column;

          >.search-demo {
            width: 100%;
            height: 48px;
            background-color: var(--data-bg-color);
            border: 1px solid var(--data-border-color);
            margin-bottom: 16px;
            border-radius: 5px;
            display: flex;
            align-items: center;
            padding-left: 20px;

            .inputGroup {
              width: 100%;
              display: flex;
              align-items: center;
              justify-content: space-between;
            }

            :deep(.arco-space-align-center) {
              margin-right: 20px;
            }

            :deep(.arco-select-view-single) {
              background-color: var(--data-input-color) !important;
              border: 1px solid var(--data-border-color);
              width: 65%;
            }

            :deep(.arco-form-layout-inline .arco-form-item) {
              width: 100%;
              margin-bottom: 0;
            }

            :deep(.arco-picker, .arco-picker) {
              background-color: var(--data-input-color) !important;
              border: 1px solid var(--data-border-color);
              // width: 280px;
            }

            :deep(.arco-feedback-icon) {
              display: none;
            }

            :deep(.arco-btn-primary) {
              background-color: var(--botton-bg-color);
            }

            :deep(.arco-btn-outline) {
              color: var(--botton-bg-color);
              border: 1px solid var(--botton-bg-color);
            }
          }

          >.statistics-demo {
            width: 100%;
            flex: 1;
          }
        }

        >.stay-time {
          width: calc(50% - 8px);
          height: 100%;
          background-color: var(--data-bg-color);
          border: 1px solid var(--data-border-color);
          border-radius: 5px;
          padding: 20px;
          display: flex;
          flex-direction: column;

          .title {
            margin-bottom: 20px;
            font-style: 'normal';
            font-weight: 600;
            font-family: 'Arial';
            font-size: 23px;
          }

          >.chart {
            width: 100%;
            flex: 1;
          }
        }
      }

      >.bottom {
        display: flex;
        justify-content: space-between;
        gap: 16px;
        height: 400px;

        >.variety {
          width: calc(35% - 12px);
          height: 400;
          background-color: var(--data-bg-color);
          border: 1px solid var(--data-border-color);
          border-radius: 5px;
          padding: 20px;
          display: flex;
          flex-direction: column;

          >.chart {
            width: 100%;
            flex: 1;
          }
        }

        >.trend {
          width: calc(70% - 8px);
          height: 400px;
          background-color: var(--data-bg-color);
          border: 1px solid var(--data-border-color);
          border-radius: 5px;
          padding: 20px;
          display: flex;
          flex-direction: column;

          .title {
            font-size: 24px;
            font-weight: 600;
            margin-bottom: 20px;
          }

          >.chart {
            width: 100%;
            flex: 1;
          }
        }
      }
      >.white-list {
        height: 500px;
      }
    }
  }
}

@media (max-width: 1200px) {

  .wrap {
    .data-demo {
      .data-demo-info {
        .top {
          flex-wrap: wrap;
          height: unset;

          .statistics {
            width: 100% !important;
            height: 300px;

          }

          .stay-time {
            width: 100% !important;
            height: 300px;

          }
        }

        // .bottom {
        //   flex-wrap: wrap;
        //   height: 300px;
        // }
      }
    }
  }
}

@media (max-width: 800px) {

  .wrap {
    .data-demo {
      .data-demo-info {
        .bottom {
          flex-wrap: wrap;
          height: 300px;

          .variety {
            width: 100%;
          }

          .trend {
            width: 100%;
          }
        }
      }
    }
  }
}
</style>